package com.zq.server.api.dao;


import java.time.LocalDateTime;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.zq.server.api.domain.entity.ApiOrders;
import com.zq.server.api.domain.vo.TicketCheckVo;

/**
 * @author Super
 * @description 针对表【orders(订单表)】的数据库操作Mapper
 * @createDate 2024-02-26 22:27:59
 * @Entity com.zq.daomain.entity.Orders
 */
@Mapper
public interface OrdersMapper {
    /**
     * @param userId 用户id
     * @param status 状态
     * @return 订单集合
     */
    @Select("SELECT * FROM api_orders WHERE user_id = #{userId} and status = #{status}")
    List<ApiOrders> getAssignStatusOrders(Long userId, Integer status);

    /**
     * 插入订单表
     *
     * @param orders
     */
    void save(ApiOrders orders);

    /**
     * 根据订单号和用户id查询订单
     *
     * @param orderNumber
     * @param userId
     */
    @Select("select * from api_orders where number = #{orderNumber} and user_id= #{userId}")
    ApiOrders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(ApiOrders orders);

    /**
     * 查询当前订单是否超时
     *
     * @param dateTime
     * @param status
     */
    @Select("select * from api_orders where status = #{status} and order_time < #{dateTime};")
    List<ApiOrders> CheckOrderTimeoutCheck(Integer status, LocalDateTime dateTime);

    /**
     * 更改所有超时订单为已取消
     *
     * @param orders
     */
    void updateOrderList(@Param("orders") List<ApiOrders> orders);

    /**
     * 获取用户所有id
     *
     * @param userId
     * @return
     */
    @Select("SELECT * FROM api_orders WHERE user_id = #{userId}")
    List<ApiOrders> getUserOrderList(@Param("userId") Long userId);

    /**
     * 查询用户今日是否参加其他活动
     *
     * @param userId
     * @return
     */

    boolean isUserJoinedActivityToday(@Param("userId") Long userId);


    /**
     * @param userId
     * @param status
     * @return
     */
    List<TicketCheckVo> getUserStayTicketCheckList(@Param("userId") Long userId, @Param("status") Integer status);

    /**
     * 用户根据手机尾号（四位）和订单id进行验票
     * @param orderId 订单id
     * @param phone   手机尾号“ 1 2 3 4  ”
     * @return 验票是否成功
     */
    Integer phoneVerificationTicket(@Param("orderId") Long orderId,@Param("phone") String phone);


    void batchInsert(List<ApiOrders> batchList);
}
